<?php

/**
 * Subclass for performing query and update operations on the 'account_supplier' table.
 *
 * 
 *
 * @package lib.model
 */ 
class AccountSupplierPeer extends BaseAccountSupplierPeer
{
  public static function search($search){
    $c = new Criteria();
    if(isset($search['company_initials']))
      $c->add(ContactPeer::COMPANY_INITIALS,'%'.$search['company_initials'].'%',Criteria::LIKE);
    if(isset($search['company_name']))
      $c->add(ContactPeer::COMPANY_NAME,'%'.$search['company_name'].'%',Criteria::LIKE);
    if(isset($search['person_name']))
      $c->add(ContactPeer::COMPANY_NAME,"(first_name like '%".$search['person_name']."%' or last_name like '%".$search['person_name']."%'",Criteria::CUSTOM);
    if(isset($search['city']))
      $c->add(ContactPeer::CITY,$search['city'].'%',Criteria::LIKE);      
    if(isset($search['country']))
      $c->add(ContactPeer::COUNTRY,$search['country'].'%',Criteria::LIKE);      
    $c->addJoin(ContactPeer::IDEN,AccountSupplierPeer::CONTACT_IDEN);
    $c->addAscendingOrderbyColumn(ContactPeer::COMPANY_NAME);
    $c->addAscendingOrderbyColumn(ContactPeer::FIRST_NAME);
    $c->addAscendingOrderbyColumn(ContactPeer::LAST_NAME);
    return ContactPeer::doSelect($c);
  }


  public static function getCompanyNameListByIden($c=null){
  	if(!($c instanceof Criteria))
  	  $c = new Criteria();
  	$c->addJoin(ContactPeer::IDEN,self::CONTACT_IDEN);
  	$c->addAscendingOrderByColumn(ContactPeer::COMPANY_NAME);
  	
  	$data = array();
  	$contacts = ContactPeer::doSelect($c);
  	foreach($contacts as $contact)
  	  $data[$contact->getIden()] = $contact->getCompanyName();
  	return $data;
  }
  
  
  public static function getCompanyNameListWithBlank($c=null){
  	if(!($c instanceof Criteria))
  	  $c = new Criteria();
  	$c->addJoin(ContactPeer::IDEN,self::CONTACT_IDEN);
  	$c->addAscendingOrderByColumn(ContactPeer::COMPANY_NAME);
  	
  	$data = array('X'=>'');
  	$contacts = ContactPeer::doSelect($c);
  	foreach($contacts as $contact)
  	  $data[$contact->getCompanyName()] = $contact->getCompanyName();
  	return $data;
  }


  public static function getPersonNameListWithBlank($c=null){
  	if(!($c instanceof Criteria))
  	  $c = new Criteria();
  	$c->addJoin(ContactPeer::IDEN,self::CONTACT_IDEN);
  	$c->addAscendingOrderByColumn(ContactPeer::LAST_NAME);
  	$c->addAscendingOrderByColumn(ContactPeer::FIRST_NAME);
  	
  	$data = array('X'=>'');
  	$contacts = ContactPeer::doSelect($c);
  	foreach($contacts as $contact)
  	  $data[$contact->getLastName().', '.$contact->getFirstName()] = 
  	    $contact->getLastName().', '.$contact->getFirstName();
  	return $data;
  }
  
  
}
